package com.frxuexi.lib_base.http

import android.content.Context
import androidx.room.Room
import com.frxuexi.lib_base.room.ParkDao
import com.frxuexi.lib_base.room.ParkDataBase
import com.frxuexi.lib_base.room.SignDao
import com.frxuexi.lib_base.room.UserDao
import com.frxuexi.lib_base.room.ZanDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Provides
    @Singleton
    fun getApiService():ApiService=RetrofitUtil.retrofit.create(ApiService::class.java)

    @Provides
    @Singleton
    fun getShopApiService():ShopApiService=RetrofitUtil.retrofitShop.create(ShopApiService::class.java)

    @Provides
    @Singleton
    fun getVideoApiService():VideoApiService=RetrofitUtil.retrofitVideo.create(VideoApiService::class.java)

    @Provides
    @Singleton
    fun initDB(@ApplicationContext context: Context):ParkDataBase{
        return Room.databaseBuilder(context,ParkDataBase::class.java,"park2305.db").allowMainThreadQueries().build()
    }

    @Provides
    @Singleton
    fun getParkDao(dataBase: ParkDataBase):ParkDao=dataBase.parkDao()

    @Provides
    @Singleton
    fun getUserDao(dataBase: ParkDataBase):UserDao=dataBase.userDao()

    @Provides
    @Singleton
    fun getSignDao(dataBase: ParkDataBase):SignDao=dataBase.signDao()

    @Provides
    @Singleton
    fun getZanDao(dataBase: ParkDataBase):ZanDao=dataBase.zanDao()
}